package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;


import org.xutils.view.annotation.ViewInject;

import java.util.Arrays;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.ui.base.BaseCustomAdapter;


/**
 * Created by Lc on 2017/12/19.
 */

public class PopListViewAdapter extends BaseCustomAdapter<String, PopListViewAdapter.ViewHolder> {
    private int backgroundColor;
    private int textColor;

    public PopListViewAdapter(Context mContext, List<String> list) {
        super(mContext, list);
    }

    public PopListViewAdapter(Context mContext, String[] list) {
        super(mContext);
        List<String> stringList = Arrays.asList(list);
        this.mList = stringList;
    }

    @Override
    protected int bindView() {
        return R.layout.item_pop_inlv;
    }

    @Override
    protected ViewHolder createViewHolder() {
        return new ViewHolder();
    }

    @Override
    protected void bindData(int position, View convertView, ViewHolder viewHolder) {
        viewHolder.textView.setText(mList.get(position));
        if (textColor != 0) {
            viewHolder.textView.setTextColor(textColor);
        }
        viewHolder.textView.setTextSize(16);
        viewHolder.textView.setGravity(Gravity.CENTER);
        if (textColor != 0) {
            convertView.setBackgroundColor(backgroundColor);
        }
    }

    class ViewHolder {
        @ViewInject(R.id.text1)
        TextView textView;
    }


    public void setColorResource(int backgroundColorResource, int textColorResource) {
        this.backgroundColor = ContextCompat.getColor(mContext, backgroundColorResource);
        this.textColor = ContextCompat.getColor(mContext, textColorResource);
    }

    public void setColor(String backgroundColor, String textColor) {
        this.backgroundColor = Color.parseColor(backgroundColor);
        this.textColor = Color.parseColor(textColor);
    }
}
